package com.lby.rabbitmq.listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @ClassName FanoutBindListener
 * @Description TODO
 * @Author louby0923
 * @Date 2024/2/2 9:51
 * @Version 1.0
 */
@Component
public class FanoutBindListener {

    /**
     * 监听queue队列消息
     *
     * @param msg
     * @throws InterruptedException
     */
  /*  // 申请式绑定，绑定queue队列也可以的
   @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "lby.fanout.queue1"),
            exchange = @Exchange(name = "lby.fanout", type = ExchangeTypes.FANOUT)))*/

    @RabbitListener(queues = "lby.fanout.queue1")
    public void fanoutReceivel(String msg) throws InterruptedException {
        Thread.sleep(500);
        System.out.println("lby.fanout.queue1 = " + msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "lby.fanout.queue2"),
            exchange = @Exchange(name = "lby.fanout", type = ExchangeTypes.FANOUT)))
    public void fanoutReceive2(String msg) throws InterruptedException {
        Thread.sleep(500);
        System.out.println("lby.fanout.queue2 = " + msg);
    }

}


